package com.yan.demo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo2 {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(10);
        list.add(20);
        list.add(30);
        list.add(40);
        System.out.println(list);
        list.remove(new Integer(30));
        System.out.println("----------------");
        System.out.println(list);
        list.remove(2);
        System.out.println(list);
        List list1 = new ArrayList();
        list1.add(1);
        list1.add(2);
        list1.add(3);
        list.addAll(1 , list1);
        System.out.println(list);
        list1.clear();
        System.out.println("---------------");
        System.out.println(list1);
        System.out.println(list.get(3));
        boolean contains = list.contains(21);
        System.out.println("contains = " + contains);
        System.out.println(list.lastIndexOf(20));
        list.set(0, 9);
        System.out.println(list);
        Iterator iterator = list.iterator();
        System.out.println("------------------");
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("----------");
        list.forEach (item -> System.out.println(item));

    }
}
